package com.zxbit.flash.presenter;

import com.zxbit.flash.BuildConfig;
import com.zxbit.flash.base.BasePresenter;
import com.zxbit.flash.common.UserInfo;
import com.zxbit.flash.mvpview.HomeMvpView;
import com.zxbit.flash.network.CustomConsumer;
import com.zxbit.flash.network.ParamsFactory;
import com.zxbit.flash.response.BannerResponse;
import com.zxbit.flash.response.ProductResponse;
import com.zxbit.flash.response.UserInformationResponse;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.functions.Consumer;

public class HomePresenter extends BasePresenter {
    private HomeMvpView mvpView;

    public HomePresenter(HomeMvpView mvpView) {
        this.mvpView = mvpView;
    }

    public void getNotice() {
        toSubScribe(req.getNotice(BuildConfig.channel, UserInfo.getToken(), ParamsFactory.getCommonParams(null)), new CustomConsumer<BannerResponse>() {
            @Override
            public void call(BannerResponse response) {
                mvpView.onGetDataNext(response);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }

    /**
     * 产品等级
     */
    public void getProduct() {
        toSubScribe(req.getProduct(BuildConfig.channel, UserInfo.getToken(), ParamsFactory.getCommonParams(null)), new CustomConsumer<ProductResponse>() {
            @Override
            public void call(ProductResponse progressResponse) {
                mvpView.onGetDataNext(progressResponse);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }


    /**
     * 获取用户退回资料的情况
     */
    public void getPersonInfoBack(String userUuid) {
        Map<String, Object> map = new HashMap<>();
        map.put("userUuid", userUuid);
        toSubScribe(req.getUserInformation(UserInfo.getToken(), ParamsFactory.getCommonParams(map)), new CustomConsumer<UserInformationResponse>() {
            @Override
            public void call(UserInformationResponse response) {
                mvpView.onGetDataNext(response);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }
}
